package com.jcnet.bizaia.adapter;

import java.util.List;

import com.androidquery.AQuery;
import com.androidquery.callback.ImageOptions;
import com.jcnet.bizaia.R;
import com.jcnet.bizaia.bean.CityBean;
import com.jcnet.bizaia.bean.CountryBean;
import com.jcnet.bizaia.bean.MainInfoBean;
import com.jcnet.bizaia.bean.SearchBean;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class SearchListAdapter extends BaseAdapter {

	private Context context;
	private List<SearchBean> searchBeans;
	public int count;
	
	private int selectedItem = -1;
	
	public SearchListAdapter(Context context, List<SearchBean> searchBeans) {
		super();
		this.context = context;
		this.searchBeans = searchBeans;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		count = searchBeans.size();
		return count;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	
	 public void setSelectedItem(int selectedItem)
      {
          this.selectedItem = selectedItem;
      }
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final ViewHolder holder;
        if(convertView == null)
        {
            holder = new ViewHolder();
            convertView = View.inflate(context,R.layout.search_list_item, null);
            holder.titleTextView = (TextView)convertView.findViewById(R.id.se_textView);
            holder.imageView = (ImageView)convertView.findViewById(R.id.se_img);
            
            convertView.setTag(holder);
        }else
        {
            holder = (ViewHolder)convertView.getTag();
            
        }
        	
        	holder.titleTextView.setText(searchBeans.get(position).getSearchName());
        	
        	/*convertView.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					holder.imageView.setVisibility(View.VISIBLE);
					notifyDataSetChanged();
				}
			});*/
        	
        	 if(position == selectedItem)
             {
                 //convertView.setBackgroundColor(Color.BLUE);
                 //convertView.setSelected(true);
                // convertView.setBackgroundResource(R.drawable.all_listentry_left_selected);
        		 holder.imageView.setVisibility(View.VISIBLE);
             }else
             {
                 //convertView.setBackgroundColor(Color.GRAY);
                 //convertView.setSelected(false);
                 //convertView.setBackgroundResource(R.drawable.lstview);
                 holder.imageView.setVisibility(View.GONE);
             }
		return convertView;
	}

	static class ViewHolder{
		TextView titleTextView;
		ImageView imageView;
	}
}
